﻿using System.Windows.Forms;

namespace Useful.GUI
{
    public class OptionalCheckBox : CheckBox
    {
        public OptionalCheckBox()
        {
            base.ThreeState = true;
        }

        public bool? Value
        {
            get
            {
                return base.CheckState != CheckState.Indeterminate ? (bool?)base.Checked : null;
            }
            set
            {
                if (value != null)
                    base.CheckState = value.Value ? CheckState.Checked : CheckState.Unchecked;
                else
                    base.CheckState = CheckState.Indeterminate;
            }
        }
    }
}